package net.maku.framework.common.config;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

@Slf4j
public class MqttConsumerCallBack implements MqttCallback  {
    /**
     * 客户端断开连接的回调
     * @param throwable
     * @return void
     */
    @Override
    public void connectionLost(Throwable throwable) {
        log.info("与服务器断开连接，可重连");

    }

    /**
     * 消息到达的回调
     * @param topic
     * @param message
     * @return void
     */
    @Override
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        log.info(String.format("接收消息主题 : %s",topic));
        log.info(String.format("接收消息Qos : %d",message.getQos()));
        log.info(String.format("接收消息内容 : %s",new String(message.getPayload())));
        log.info(String.format("接收消息retained : %b",message.isRetained()));
    }

    /**
     * 消息发布成功的回调
     * @param iMqttDeliveryToken
     * @return void
     */
    @Override
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {

    }

}

